package com.crazy.boot.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.crazy.boot.entity.User;
import com.crazy.boot.service.UserService;
import com.crazy.boot.util.ResultUtils;

@RestController
@RequestMapping("/index")
public class IndexController {

	@Autowired
	private UserService userService;
	
	@GetMapping("/login")
	public ResultUtils login(String name, String password, boolean rememberMe) {
		User user = userService.login(name, password, rememberMe);
		if(user!=null) {
			return ResultUtils.toClient("0", "success", 0, user);
		}else {
			return ResultUtils.toClient("0", "fail", 0, user);
		}
	}
	
	@PostMapping("/register")
	public ResultUtils register(String name, String password) {
		User user = userService.getUserByName(name);
		return ResultUtils.toClient("0", "success", 0, user);
	}
	
	@GetMapping("/UnLogin")
	public ResultUtils UnLogin(String name, String password) {
		return ResultUtils.toClient("0", "您还没有登录");
	}
	
	@GetMapping("/UnAuthorized")
	public ResultUtils UnAuthorized(String name, String password) {
		return ResultUtils.toClient("0", "您没有该操作的权限");
	}
}